{template 'common/header'}

<link rel="stylesheet" href="/web/resource/components/ueditor/themes/default/css/ueditor.css">
<form action="{php echo $this->createWeburl('addstore');}" method="post" class="form-horizontal" onsubmit="return checkStoreName()">
    <div class="panel panel-default">
        <div class="panel-heading">编辑店铺</div>
        <div class="panel-body">
            <div class="clearfix">
                <div class="alert alert-warning alert-dismissible fade in" id="notice" style="display: none" role="alert">
                </div>


                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger"> </span>店铺名称:</label>
                    <div class="col-sm-9 col-xs-12">
                        <input id="storename" required type="text" name="storename" value="{$row['storename']}" class="form-control"/>
                    </div>

                </div>



                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger"> </span>店铺简介:</label>

                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_ueditor('storedesc',$row['storedesc']);}
                    </div>

                </div>


                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger"> </span>属性:</label>
                    <div class="col-sm-9 col-xs-12">

                        <div class="panel panel-default">

                            <div class="panel-body">
                                {loop $attrs $attr}

                                    <label class="checkbox-inline">

                                            <input attr-storeid = {$row['id']} class="attr-checkbox" {php $this->getCheckedBox($attr['id'],$storeAttrIds)} name="storeattr[]" type="checkbox" id="inlineCheckbox1" value="{$attr['id']}"> {$attr['value']}

                                    </label>

                                {/loop}
                            </div>
                        </div>

                    </div>
                </div>



                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="hidden" name="token" value="{$_W['token']}"/>
                        <input type="hidden" name="submit" value="submit"/>
                        <input type="hidden" name="update_store_id" value="{$row['id']}">
                        <input type="submit"  name="submit" value="提交" class="btn btn-primary"/>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>


<script>

    $(document).ready(function () {
        listenCheckBox();
    })

    /**
     * 监听checkBox
     */
    function listenCheckBox() {
        $(".attr-checkbox").on('change',function () {
            var attr_id = $(this).val();
            var store_id = $(this).attr('attr-storeid');

            $.post("{php echo $this->createWeburl('UpdateStoreAttr')}",
                {attr_id:attr_id,store_id:store_id},
                function(data) {

                    if(data.errCode == 0){
                        util.message(data.msg, '', 'success');
                    }else{
                        util.message(data.msg,'','error');
                    }
                },"JSON");


        })
    }

</script>


<script>

    function checkStoreName() {
        var storename = $("#storename").val();
        var bool = true;
        $.ajax({
            type : "POST",
            url : "{php echo $this->createWeburl('checkstore');}",
            data : {storename:storename,update_store_id:{$row['id']}},
            async : false,
            dataType: 'json',
            success : function(result){
                if(result.errorCode != 0){
                    $("#notice").text('提示: ' + result.message);
                    $("#notice").show();
                    bool = false;
                }else{
                    $("#notice").hide();
                    bool = true;
                    console.log(bool);
                }
            }
        });
        return bool;
    }
</script>
{template 'common/footer'}

